package cn.pconline.officialclub.web.admin;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.gelivable.webmvc.JSONBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author ppc
 */
public class AdminControllerKit {

    private static final Logger log = LoggerFactory.getLogger(AdminControllerKit.class);
    protected static final int DEF_PAGE_NO = 1;
    protected static final int DEF_PAGE_SIZE = 20;
    protected void errorMsg(String msg, HttpServletResponse resp) {
        try {
            resp.setCharacterEncoding("UTF-8");
            resp.getWriter().println(
                    new JSONBuilder()
                    .put("statusCode", 300)
                    .put("message", msg)
                    .toString());
        } catch (IOException ex) {
            log.error("set errorMsg fail!", ex);
        }
    }

    /**
     * 成功返回消息
     *
     * @param resp
     * @param navTabId
     * @param msg
     * @param callbackType closeCurrent 关闭当前tab forward reload
     */
    protected void successMsg(HttpServletResponse resp, String navTabId, String msg, String callbackType) {
        try {
            resp.setCharacterEncoding("UTF-8");
            PrintWriter out = resp.getWriter();
            out.println(new JSONBuilder().put("statusCode", 200).put("message", msg).put("navTabId", navTabId).put("callbackType", callbackType).toString());
        } catch (IOException ex) {
            log.error("set successMsg fail!", ex);
        }
    }
}
